<template>
  <div id="app">
    <Topbar :key="topbar" />
    <Header />
    <router-view @upkey="getVal" />
    <Footer />
    <login v-if="isShowLoginModal"></login>
    <transition name="slide"> <Toast v-if="isShowToast" />\ </transition>
  </div>
</template>
<script>
import Topbar from "@/components/topbar.vue";
import Header from "@/components/header.vue";
import Footer from "@/components/footer.vue";
import login from "@/components/login.vue";
import Toast from "@/components/Toast.vue";
import { mapState } from "vuex";
import { jingpinapi } from "@/request/api.js";
export default {
  data() {
    return {
      topbar: "",
    };
  },
  components: {
    Footer,
    Header,
    Topbar,
    login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  created() {
    /*  
    1.地址每次都是很长一段，一旦后续修改，改动地方也会增多 （接口管理）
    解决方案:对axios进行统一封装 request=>request.js
2.每次都需要设置请求头携带token （请求头）
3.请求a完成后再请求b出现回调地狱 （回调地狱）
    */
  },
  methods: {
    // fn() {
    //   jingpinapi().then((res) => {
    //     console.log(res);
    //     // console.log(res.data.data.data.records);
    //   });
    // },
    async fn() {
      //await 可以是一个promise对象,必须放在asyns的修饰函数里
      let res = await jingpinapi();
      // console.log("app-res1:", res);
      let res2 = await jingpinapi();
      // console.log("app-res2:", res2);
    },
    getVal() {
      this.topbar++;
    },
  },
  watch: {
    "$route.path": {
      handler() {
        this.topbar++;
      },
    },
  },
};
</script>
<style lang="less">
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
